package org.zoomdev.zoom.rpc.utils;

import io.netty.buffer.ByteBuf;

public class MessageEncoder {


    public static void encode(ByteBuf sendBuffer, int id, short func, byte[] bytes) {
        sendBuffer.writeByte(0xcc);
        if (bytes != null) {
            sendBuffer.writeInt(bytes.length);
            sendBuffer.writeInt(id);
            sendBuffer.writeShort(func);
            sendBuffer.writeBytes(bytes);
        } else {
            sendBuffer.writeInt(0);
            sendBuffer.writeInt(id);
            sendBuffer.writeShort(func);
        }
        sendBuffer.writeByte(0xca);
    }

}
